const list = ['dataType', 'dataCode', 'dataValue'];
import { numberValidator } from '@/utils/form-validator';
function getRules(list: (string | string[] | any[])[]) {
  const resRules: Record<string, any> = {};
  list.forEach(item => {
    const [name, type] = typeof item === 'string' ? [item] : item;
    resRules[name] = [
      {
        required: true,
        message: '必填项',
        trigger: ['submit', 'blur', 'change']
      }
    ];
    if (type === 'rate')
      resRules[name].push({
        min: 0,
        max: 100,
        message: '请输入正确格式: 0-100',
        trigger: ['submit', 'blur', 'change'],
        validator: (rule: any, value: string, callback: Fn) => {
          if (Number(value) < 0 || Number(value) > 100) {
            callback(new Error('请输入正确格式: 0-100'));
          } else {
            callback();
          }
        }
      });
    if (name === 'sort') resRules[name].push(numberValidator(6, false, false));
    //
  });
  return resRules;
}

export const rules = getRules(list);
